package com.xingcheng;

import com.xingcheng.discord.midjourney.EventHandle;
import com.xingcheng.discord.midjourney.EventMessageListener;
import com.xingcheng.discord.midjourney.WebSocketClient;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xingchen
 * @version 1.0.0
 * @title App
 * @description
 * @create 2023/12/31 17:02
 **/
@SpringBootApplication(scanBasePackages = {"com.xingcheng"})
@Service
@RequiredArgsConstructor
public class App implements ApplicationRunner {

    private final List<EventHandle> eventHandles;

    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        String proxyHost="";
        Integer proxyPort=0;
        /**
         * use  user token
         */
        String token="";
        EventMessageListener messageListener = new EventMessageListener(eventHandles);
        WebSocketClient client = new WebSocketClient(proxyHost, proxyPort, token,messageListener);
        try {
            client.connect();
            while (!client.isConnected()) {
                Thread.sleep(100);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
